package com.company.zonghelizi.jihe.myjihe;

import java.util.Arrays;

/**
 * 根据key找到特定的一个数据
 * 散列码：
 * 负载因子：桶的个数*0.75（加载因子） 然后根据数组里的内容数量比较，内容比它大就扩容
 */
public class MyHashMap {
    private Entry[] arr = new Entry[5];
    private int size;
    public void put(Object key,Object value){
        if(size==arr.length){
            this.arr = Arrays.copyOf(arr,arr.length+5);
        }
        arr[key.hashCode()%arr.length] = new Entry(key,value);
    }
    public Object get(Object key){
        return arr[key.hashCode()%arr.length];
    }
}

// 一对键值对
class Entry{
    private Object key;
    private Object value;

    public Entry(Object key, Object value) {
        this.key = key;
        this.value = value;
    }

    public Object getKey() {
        return key;
    }

    public void setKey(Object key) {
        this.key = key;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return "Entry{" +
                "key=" + key +
                ", value=" + value +
                '}';
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}
